package com.liujg.future.model.resp;

import com.alibaba.fastjson2.JSON;
import com.google.common.collect.Lists;
import lombok.Data;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Data
public class LogisticsVO {

    /**
     * 快递公司
     */
    private Company company;
    /**
     * 物流日志
     */
    private List<Logistics> list;

    /**
     * 商品图片
     */
    private String picture;
    /**
     * 商品件数
     */
    private Integer count;
    @Data
    public static class Company {
        /**
         * 快递公司名称
         */
        private String name;
        /**
         * 快递单号
         */
        private String number;
        /**
         * 联系电话
         */
        private String tel;
    }

    @Data
    public static class Logistics {
        /**
         * 信息ID
         */
        private String id;
        /**
         * 信息文字
         */
        private String text;
        /**
         * 时间 格式：2024-09-03 15:21:13
         */
        private String time;
    }

    public LogisticsVO() {
    }

    public static LogisticsVO getLogisticsVO(Integer count,String picture,String consignTime){
        LogisticsVO logisticsVO = new LogisticsVO();
        Company company = new Company();
        List<Logistics> list = Lists.newArrayList();

        company.setName("中通快递");
        company.setNumber("10000000069494");
        company.setTel("43725472");

        logisticsVO.setCount(count);
        logisticsVO.setPicture(picture);
        logisticsVO.setCompany(company);
        logisticsVO.setList(list);

        LocalDateTime time =  LocalDateTime.parse(consignTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        String listJson = String.format("""
                [
                            {
                                "id": "1829419081774665730",
                                "text": "小兔兔到了小福家里，请签收",
                                "time": "%s"
                            },
                            {
                                "id": "1829419081770471426",
                                "text": "小兔兔到了小熊站，小站正在赶往目的地",
                                "time": "%s"
                            },
                            {
                                "id": "1829419081770471425",
                                "text": "小兔兔到了小猴站，小站正在分发偶",
                                "time": "%s"
                            },
                            {
                                "id": "1829419081766277122",
                                "text": "小兔兔已经发货了",
                                "time": "%s"
                            }
                        ]
                """,
                time.plusDays(4).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")),
                time.plusDays(3).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")),
                time.plusDays(2).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")),
                time.plusDays(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));

        List<Logistics> logistics = JSON.parseArray(listJson, Logistics.class);
        list.addAll(logistics);
        return logisticsVO;

    }
}
